<template>
    <div style="width: 100%">
        <el-cascader v-if="!isInstanceSearch" :style="selectStyle" :disabled="isDisable" :options="optionsList"
                     v-model="properties.bindValue" :placeholder="properties.selectPlaceHolder"
                     :clearable="properties.isClearable" :filterable="properties.isFilterable"
                     :multiple="properties.isMultiple" :props="defaultProps"
                     :collapse-tags="properties.isMultiple && properties.isCollapseTags"
                     :collapse-tags-tooltip="properties.isMultiple && properties.isCollapseTags && properties.isCollapseTagsTooltip"
                     :max-collapse-tags="properties.isMultiple && properties.isCollapseTags ? properties.maxCollapseTags : ''"/>

        <el-cascader v-if="isInstanceSearch" :style="selectStyle" :disabled="isDisable" :options="optionsList"
                     v-model="properties.searchValue" :placeholder="properties.selectPlaceHolder"
                     :clearable="properties.isClearable" :filterable="properties.isFilterable"
                     :multiple="properties.isMultiple" :props="defaultProps"
                     :collapse-tags="properties.isMultiple && properties.isCollapseTags"
                     :collapse-tags-tooltip="properties.isMultiple && properties.isCollapseTags && properties.isCollapseTagsTooltip"
                     :max-collapse-tags="properties.isMultiple && properties.isCollapseTags ? properties.maxCollapseTags : ''"/>

    </div>
</template>

<script setup lang="ts" name="YwuFormCascaderSelect">

import {computed, defineProps, ref} from "vue";
import {doFromInfoValue} from "@/views/bpmn/form/formUtils.ts";

let props = defineProps(['isEdit', 'properties', 'isInstanceSearch', "isDisable", "formBuildList"]);

let isEdit = computed(() => {return props['isEdit']})
let properties = computed(() => {return props['properties']})
let isInstanceSearch = computed(() => {return props['isInstanceSearch']})
let isDisable = computed(() => {return props['isDisable']})
let formBuildList = computed(() => {return props['formBuildList']})

let optionsList = ref([])

let defaultProps = computed(() => {
    return {
        children: properties.value.optionChildren,
        label: properties.value.optionLabel,
        value: properties.value.optionValue,
        multiple: isInstanceSearch.value ? false : properties.value.isMultiple
    }
})

let selectStyle = computed(() => {
    if (isEdit.value) {
        return "pointer-events: none;width: 100%"
    } else {
        return "width: 100%";
    }
})

function execFunc(resList) {
    optionsList.value = resList
}

init()
function init() {
    doFromInfoValue(properties.value, formBuildList.value, execFunc)
}
</script>

<style scoped lang="less">

</style>